home *** CD-ROM | disk | FTP | other *** search
- { Listing 1 }
- procedure CreateModal(FormClass: TFormClass);
- begin
- with FormClass.Create(Application) do
- try
- ShowModal
- finally
- Free
- end
- end;
-
- { Listing 2 }
- constructor TmbDBNavigator.Create(AOwner: TComponent);
- var
- I: TNavigateBtn;
- begin
- inherited Create(AOwner);
- for I := Low(Buttons) to High(Buttons)
- do Buttons[I].OnClick := Click;
- end;
- procedure TmbDBNavigator.Click(Sender: TObject);
- begin
- BtnClick (TNavButton (Sender).Index);
- end;
-
- { Listing 3 }
- {(C) 1996 Pijl Computer Services Ltd. Check laptop power situation}
- Unit Power;
- Interface
- Function PowerMan:Integer;
- Implementation
- Function PowerMan:Integer;
- Var
- Fault,Batt,Life:Byte;
- begin
- asm
- mov fault,00h
- mov ax,5300h
- mov bx,0000h
- int 15h
- jc @err
- mov ax,530ah
- mov bx,0001h
- int 15h
- mov batt,bl
- mov life,cl
- jc @err
- jmp @done
- @err: mov fault,AH
- @done: nop
- end;
- If (Fault=0) aAnd (Life in [0..100]) then
- PowerMan := Life
- else
- PowerMan := -1;
- end;
- end.
-
- { Listing 4 }
- type
- PMyRecord = ^TMyRecord;
- TMyRecord = record
- Field : longint;
- end;
- PMyArray = ^TMyArray;
- TMyArray = array[0..100-1] of longint;
- PMySimpleType = ^TMySimpleType;
- TMySimpleType = Double;
- var
- tMyRec : TMyRecord;
- pMyRec : PMyRecord;
- tMyArr : TMyArray;
- pMyArr : PMyArray;
- tMySim : TMySimpleType;
- pMySim : PMySimpleType;
- procedure NoHat;
- begin
- { Initialize pointer variables }
- pMyRec := @tMyRec;
- pMyArr := @tMyArr;
- pMySim := @tMySim;
- { Test normal assignment }
- pMyRec^.Field := 1234567;
- pMyArr^[0] := 1234567;
- pMySim^ := 3.14;
- { Test the no-hat assignment }
- pMyRec.Field := 1234567; { Compiles fine! }
- pMyArr[0] := 1234567; { Compiles fine! }
- { This last one does not compile and should not }
- pMySim := 3.14;
- end;
-
- { Listing 5 }
- type
- TStrong = type Double;
- TWeak = Double;
- procedure CheckWeak(var Strong: TWeak); begin end;
- procedure CheckStrong(var Strong: TStrong); begin end;
- procedure CheckDouble(var D: Double); begin end;
- var
- D: Double;
- S: TStrong;
- W: TWeak;
- begin
- CheckDouble(D); { compiles fine }
- CheckDouble(W); { compiles fine }
- CheckDouble(S); { <- compile error }
- CheckWeak(D); { compiles fine }
- CheckWeak(W); { compiles fine }
- CheckWeak(S); { <- compile error }
- CheckStrong(S); { compiles fine }
- CheckStrong(D); { <- compile error }
- CheckStrong(W); { <- compile error }
- end.
-
- { Listing 6 }
- unit NewPC;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics,
- Controls, Forms, Dialogs, ComCtrls;
- type
- TNewPageControl = class(TPageControl)
- private
- procedure CMDialogChar(var Message: TCMDialogChar);
- message CM_DIALOGCHAR;
- protected
- public
- published
- end;
- procedure Register;
- implementation
- procedure Register;
- begin
- RegisterComponents('Samples', [TNewPageControl]);
- end;
- procedure TNewPageControl.CMDialogChar(var Message: TCMDialogChar);
- var
- I: Integer;
- S: String;
- begin
- if Enabled then with Message do begin
- for I := 0 to PageCount - 1 do begin
- S := Pages[I].Caption;
- if IsAccel(CharCode, S) and Pages[I].TabVisible then begin
- { select the appropriate Tab and give it focus }
- Result := 1; { accelerator key is valid (don't beep) }
- ActivePage := Pages[I];
- if ActivePage = Pages[I] then
- { successfully changed pages }
- Change;
- Exit;
- end;
- end;
- end;
- inherited;
- end;
- end.